package com.bgs.travelapp.card.controller;

import com.bgs.travelapp.card.entity.CardDetailsEntity;
import com.bgs.travelapp.card.service.CardDetailsService;
import com.bgs.travelapp.page.PageRequest;
import com.bgs.travelapp.page.PageResult;
import com.bgs.travelapp.result.CommonResult;
import org.apache.commons.collections4.Get;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * gpd
 * 会员卡详情修改功能 （后端）
 * 2022-07-25
 */
@RestController
@CrossOrigin
@RequestMapping("/cardDetails")
public class CardDetailsController {
    @Resource
    CardDetailsService cardDetailsService;

    /**
     * 查询会员卡类型 （后端---会员卡详情）
     * gpd 2022-08-02 17:09
     * @return
     */
    @GetMapping("/getSelectCard")
    public CommonResult getSelectCard(){
        return CommonResult.ok(cardDetailsService.getSelectCard());
    }

    /**
     * 分月全查+模糊查（会员卡名称） （后端---会员卡详情）
     * gpd 2022-08-02 17:09
     * @param pageRequest
     * @return
     */
    @GetMapping("/getCardDetailsByPage")
    public PageResult getCardDetailsByPage(PageRequest pageRequest,String cardName){
        return cardDetailsService.getCardDetailsByPage(pageRequest,cardName);
    }

    /**
     * 新增会员卡详情  （后端---会员卡详情）
     * gpd 2022-08-02 17:14
     * @param cardDetailsEntity
     * @return
     */
    @PostMapping("/saveCardDetails")
    public CommonResult saveCardDetails(@RequestBody CardDetailsEntity cardDetailsEntity){
        return CommonResult.ok(cardDetailsService.saveCardDetails(cardDetailsEntity));
    }

    /**
     * 新增修改校验方法--查询月份是否重复录入 （后端---会员卡详情）
     * gpd 2022-08-02 17:14
     * @param purchaseMonth
     * @param cardId
     * @return
     */
    @GetMapping("/selectCardDetailsPurchaseMonth")
    public CommonResult selectCardDetailsPurchaseMonth(Integer purchaseMonth,Integer cardId){
        return CommonResult.ok(cardDetailsService.selectCardDetailsPurchaseMonth(purchaseMonth,cardId));
    }

    /**
     * 修改会员卡详情 （后端---会员卡详情）
     * gpd 2022-08-02 17:15
     * @param cardDetailsEntity
     * @return
     */
    @PutMapping("/updateCardDetails")
    public CommonResult updateCardDetails(@RequestBody CardDetailsEntity cardDetailsEntity){
        return CommonResult.ok(cardDetailsService.updateCardDetails(cardDetailsEntity));
    }

    /**
     * 删除会员卡详情 （后端---会员卡详情）
     * gpd 2022-08-02 17:15
     * @param id
     * @return
     */
    @DeleteMapping("/deleteCardDetails")
    public CommonResult deleteCardDetails(Integer id){
        return CommonResult.ok(cardDetailsService.deleteCardDetails(id));
    }
}
